Skip to content

Instantly share code, notes, and snippets.

@sukima
sukima / machine.js
Created February 7, 2020 14:57
Generated by XState Viz: https://xstate.js.org/viz
const FORM_MANAGER = {
id: 'rule-form-manager',
initial: 'blank-form',
states: {
'blank-form': {
on: {
PICK_ADDRESS_FAMILY: [
{ target: 'ipv4-address-any-port', cond: (_, { value }) => value === 'IP4' },
{ target: 'ipv6-address-any-port', cond: (_, { value }) => value === 'IP6' },
{ target: 'any-address-any-port', cond: (_, { value }) => value === 'ANY' },
@sukima
sukima / machine.js
Last active May 9, 2024 23:55
Generated by XState Viz: https://xstate.js.org/viz
function createMachine() {
return Machine({
id: 'example-form-manager',
type: 'parallel',
context: {
canSelectNone: true,
advancedProtocol: '',
ip4Address: '',
ip6Address: ''
},
@sukima
sukima / machine.js
Last active May 9, 2024 23:55
Generated by XState Viz: https://xstate.js.org/viz
const parseScannedData =
(context, event) => {
return (callback) => {
// This should be something that gets the json:
let { json } = {} // doSomethingAsync();
let isValid = Array.isArray(json);
if (!isValid) {
callback({ type: 'SCAN_ERROR' });
} else {
@sukima
sukima / adapters.application.js
Created August 16, 2018 16:31
Not serializing ember-data attrs
import DS from 'ember-data';
let id = 0;
function uniqId() {
id++;
return `${id}`;
}
export default DS.JSONAPIAdapter.extend({
ajax(url, method, { data }) {
lookupFactory(refName) {
// lookupMethod was moved to _lookupFactory in Ember 2.x+
// This is a well used API in the community but was never officially made
// public. Core team is in the process of making an official API for
// factories. Till then this is the only way to lookup factories from the
// registry. https://github.com/emberjs/rfcs/pull/150
const owner = getOwner(this);
const lookupFactory = owner._lookupFactory || owner.lookupFactory;
return lookupFactory.call(owner, refName);
}
@sukima
sukima / slack.vim
Last active May 9, 2024 23:54
Slack syntax highlighting for vim
" Vim syntax file
" Language: Slack
" Maintainer: Devin Weaver <suki@tritarget.org>
if exists("b:current_syntax")
finish
endif
syn case ignore
@sukima
sukima / httpPromise.js
Last active May 9, 2024 23:54
Turn TW5 httpRequest into a Promise API
function httpPromise(url, method, data) {
if (!data) {
data = method;
methos = 'GET';
}
return new Promise(function(resolve, reject) {
var http = $tw.utils.httpRequest({
url: url,
type: method,
data: data,
From 7c7e8615860eb40da0e95ae41d9f750079ac9eb4 Mon Sep 17 00:00:00 2001
From: Said <saidmoya12@gmail.com>
Date: Mon, 18 Apr 2016 14:45:03 -0500
Subject: [PATCH] Resize with device orientation changes
When a mobile device changes orientation it does not trigger the
`resize` event like a normal window resize would. This means on mobile
devices that changing the orientation does not cause the pannellum
canvas to resize. This commit resizes based on the `orientationchange`
event.
@sukima
sukima / AllPublicTiddlers.html.tid
Created March 24, 2016 10:34
Public/Private TiddlyWiki commands
title: $:/core/templates/allpublictiddlers.template.html
type: text/vnd.tiddlywiki-html
<!-- This template is provided for backwards compatibility with older versions of TiddlyWiki -->
<$set name="exportFilter" value="[!is[system]!tag[private]sort[title]]">
{{$:/core/templates/exporters/StaticRiver}}
</$set>
@kvedala
kvedala / main.go
Created May 27, 2022 21:03
Generating JWT Tokens with random secret key in golang
package main
import (
"crypto/hmac"
"crypto/sha512"
"fmt"
"log"
"math/rand"
"time"